﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>班组管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../js/formSelects/formSelects-v4.css">
</head>
<body>
<div style="padding: 10px;">
    <from class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: auto;">所属项目</label>
                <div class="layui-input-inline" style="width: 300px">
                    <select name="projectName"  id="projectName" xm-select="projectName" xm-select-show-count="1" xm-select-search=""   lay-search="">
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width: auto;">班组名称</label>
                <div class="layui-input-inline" style="width: 130px;">
                    <input type="text" id="banzuname" name="banzuname" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label" style="width: auto;">所属劳务公司</label>
                <div class="layui-input-inline" style="width: 130px;">
                    <input type="text" id="companyName" name="companyName" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layui-btn-normal" data-type="search" id="btnSearch">查询</button>
                <button class="layui-btn layui-btn-primary" data-type="doAdd" id="btnAdd">新增班组</button>
<!--                <button class="layui-btn layui-btn-danger" data-type="doSend" id="btnSend">工资上报结果</button>-->
<!--                <button class="layui-btn layui-btn-danger" data-type="doPay" id="btnPerPay">单员工工资上报</button>-->
            </div>
        </div>

    </from>
</div>
<table class="layui-table" lay-filter="tbFliter" id="tbData" style="margin-top: -25px;">
</table>
<script type="text/html" id="barList">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="send">工资填报</a>
</script>
<script src="../assets/layui/layui.js"></script>
<script>
    layui.config({
        base: '../js/'
    })
        .extend({
            formSelects: 'formSelects/formSelects-v4'
        });;
    layui.use(['jquery','table','common','laydate','formSelects'], function () {
        var table = layui.table,
            common=layui.common,
            layer = layui.layer,
            laydate=layui.laydate,
            formSelects = layui.formSelects,
            $ = layui.jquery;
        
        formSelects.config("projectName",{
            keyName: 'name',
            keyVal: 'code'})
            .data("projectName","server",{
                url: '../project/getSelectByProject?ddtype=project_company',
                success: function(id, url, searchVal, result){
                    formSelects.value('projectName',result);
                }
            });
            active = {
                search: function () {
                    table.reload("tbOptions", {
                        where: {
                            banzuname: $("#banzuname").val(),
                            companyName: $("#companyName").val(),
                            projectname:formSelects.value('projectName', 'valStr'),
                            page:1
                        }
                    });
                },
                doSend: function () {
                    common.layer_show("工资上报结果",'projectCompSendList.html','100%','100%');
                },
                doAdd: function () {
                    common.layer_show("班组新增",'projectCompAdd.html','100%','100%');
                },
                doPay: function () {
                    common.layer_show("员工工资上报",'../person/personPay.html','100%','100%');
                },
                doImport:function () {

                },
                doExport:function () {

                }
            };
        // var personlist="";
        // $.ajax({
        //     url: "../project/getperson",
        //     dataType: "json",
        //     success: function (rtn) {
        //         if (rtn && rtn.code===0) {
        //             personlist= rtn.data;
        //         }
        //     }
        // });
        //表格初始化
        table.render({
            elem: '#tbData'
            , skin: 'row'
            , url: '../project/banzulist'
            , page: true
            , cols: [[
                {field: 'banzu_name', title: '班组名称',width: 380, templet: function (d) {
                        if(d.alram=="1")
                        {
                            return '<label ><img onmouseover=showTips(this,"该班组当月工资还未下发",2) src="../images/alarm.jpg" width="20px" height="20px" />'+d.banzu_name+'</label>';
                        }else{
                            return '<label>'+d.banzu_name+'</label>';
                        }
                    }}
                ,{field: 'number', title: '人数',width: 100}
                ,{field: 'banzu_person', title: '班组负责人',width: 100}
                ,{field: 'banzu_person_phone', title: '班组负责人电话',width: 150}
                // , {field: 'status', title: '状态',templet: function(d){
                //     if(d.status==1){
                //         return '待审核';
                //     }else  if(d.status==2){
                //         return '审核通过';
                //     }else  if(d.status==3){
                //         return '审核不通过';
                //     }
                //     return "";
                // }}
                , {
                    field: 'operation', title: '操作', templet: function (d) {
                        if (d.status == 0) {
                            var html = '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>';
                            html += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="qiyong">启用</a>';
                            return html;
                        } else if (d.status == 2) {
                            var html = '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>';
                            html += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                            return html;
                        } else {
                            var html = '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>';
                            html += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
                            html += '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="send">工资上报</a>';
                            // html += '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="send">班组工资填报</a>';
                            // html += '<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="perPay">单个员工工资填报</a>';
                            return html;
                        }
                        return "";
                    }
                }
            ]]
            , limits: [10, 20, 50]
            , where: {
                banzuname: $("#banzuname").val(),
                projectname:formSelects.value('projectName', 'valStr'),
                companyName: $("#companyName").val()
            }
            , id: 'tbOptions'
        });

        table.on('tool(tbFliter)', function (obj) {
            var data = obj.data; //获得当前行数据
            var projectname = data.projectname;
            var projectid = data.projectid;
            var licno = data.licno;
            var profession = data.profession;
            var banzu_name = data.banzu_name;
            var banzu_id = data.id;
            var id = data.id;
            var number = data.number;
            var layEvent = obj.event; //获得 lay-event

            // var list = data.number.split(",");
             var html = "";
            // for (var i = 0; i < list.length; i++) {
            //     for (var m = 0; m < personlist.length; m++) {
            //         if (list[i] == personlist[m].code) {
            //             html += personlist[m].name+",";
            //         }
            //     }
            // }
            // html=html.substring(0,html.length-1);

            if (layEvent === 'edit') { //编辑
                common.layer_show("班组信息编辑", 'projectCompEdit.html?id=' + id, '100%', '100%');
            } else if (layEvent === 'del'||layEvent === 'qiyong') { //删除
                var str="删除";
                if (layEvent === 'qiyong'){
                    str='启用';
                }
                layer.confirm('您确定'+str+'该班组吗？', function (index) {
                    $.ajax({
                        type: 'POST',
                        url: '../project/deletebanzu',
                        dataType: 'json',
                        data: {id: id,status:layEvent},
                        success: function (rtn) {
                            if (rtn.code == 0) {
                                common.showMsg('操作成功!');
                                table.reload("tbOptions", {
                                    where: {
                                        projectName: $("#projectName").val(),
                                        companyName: $("#companyName").val()
                                    },page:{
                                        curr: 1
                                    }
                                });
                            }
                            else {
                                common.showError("操作失败:" + rtn.msg);
                            }
                        },
                        error: function () {
                            common.showError("操作失败");
                        }
                    });
                });
            }else  if (layEvent === 'send'){
                common.layer_show("班组工资填报", 'projectCompSend.html?projectname=' + encodeURIComponent(projectname)+'&projectid='+projectid+'&licno='+encodeURIComponent(licno)+'&profession='+profession+'&banzu_name='+encodeURIComponent(banzu_name)+'&banzu_id='+banzu_id+'&number='+encodeURIComponent(number)+'&namelist='+encodeURIComponent(html), '100%', '100%');
            }
            else  if (layEvent === 'perPay'){
                common.layer_show("员工工资上报",'../person/personPay.html','100%','100%');
            }
        });

        //按钮事件绑定
        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    function showTips(obj,content,options) {
        layer.tips(content, obj, options)
    }
</script>
</body>
</html>